package com.repair.repairSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.repair.common.annotation.Log;
import com.repair.common.core.controller.BaseController;
import com.repair.common.core.domain.AjaxResult;
import com.repair.common.enums.BusinessType;
import com.repair.repairSys.domain.RepairUsers;
import com.repair.repairSys.service.IRepairUsersService;
import com.repair.common.utils.poi.ExcelUtil;
import com.repair.common.core.page.TableDataInfo;

/**
 * 维修用户Controller
 * 
 * @author repair
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/repairSys/users")
public class RepairUsersController extends BaseController
{
    @Autowired
    private IRepairUsersService repairUsersService;

    /**
     * 查询维修用户列表
     */
    @PreAuthorize("@ss.hasPermi('repairSys:users:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairUsers repairUsers)
    {
        startPage();
        List<RepairUsers> list = repairUsersService.selectRepairUsersList(repairUsers);
        return getDataTable(list);
    }

    /**
     * 导出维修用户列表
     */
    @PreAuthorize("@ss.hasPermi('repairSys:users:export')")
    @Log(title = "维修用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairUsers repairUsers)
    {
        List<RepairUsers> list = repairUsersService.selectRepairUsersList(repairUsers);
        ExcelUtil<RepairUsers> util = new ExcelUtil<RepairUsers>(RepairUsers.class);
        util.exportExcel(response, list, "维修用户数据");
    }

    /**
     * 获取维修用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('repairSys:users:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return success(repairUsersService.selectRepairUsersByUserId(userId));
    }



    /**
     * 新增维修用户
     */
    @PreAuthorize("@ss.hasPermi('repairSys:users:add')")
    @Log(title = "维修用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairUsers repairUsers)
    {
        return toAjax(repairUsersService.insertRepairUsers(repairUsers));
    }

    /**
     * 修改维修用户
     */
    @PreAuthorize("@ss.hasPermi('repairSys:users:edit')")
    @Log(title = "维修用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairUsers repairUsers)
    {
        return toAjax(repairUsersService.updateRepairUsers(repairUsers));
    }

    /**
     * 删除维修用户
     */
    @PreAuthorize("@ss.hasPermi('repairSys:users:remove')")
    @Log(title = "维修用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(repairUsersService.deleteRepairUsersByUserIds(userIds));
    }
}
